home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / ms-termcap < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  45.1 KB

  1. From: root@nccnat.UUCP (Paul Shields)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i100: GNU Termcap ported to MS-DOS.
  4. Message-ID: <8804202315.0.UUL1.2#235@nccnat.UUCP>
  5. Date: 21 Apr 88 04:15:16 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 100
  9. Submitted-By: "Paul Shields" <root@nccnat.UUCP>
  10. Archive-Name: ms-termcap
  11.  
  12. Here is GNU Termcap, from GNU Emacs, ported to MS-DOS.  I find
  13. this quite useful with an ansi screen driver, and have managed to get 
  14. Micro Emacs to work over the RS232 port this way.
  15.  
  16. Sorry about the fact that there's no documentation. Please refer to the
  17. termcap library documentation for Unix.  One last note: please examine
  18. config.h for possible changes. 
  19.  
  20. Paul Shields,            York University, Toronto Canada
  21. shields@yunccn.UUCP        
  22. or yunccn!nccnat!root.        
  23.  
  24. ---------------- cut here ----------------
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then unpack
  27. # it by saving it into a file and typing "sh file".  To overwrite existing
  28. # files, type "sh file -c".  You can also feed this as standard input via
  29. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  30. # will see the following message at the end:
  31. #        "End of shell archive."
  32. # Contents:  CONFIG.H FILES.LS MAKEFILE.LC MAKEFILE.SCO MK.BAT
  33. #   TERMCAP.C TEXTERN.C TPARAM.C
  34. # Wrapped by root@nccnat.UUCP on Wed Apr 20 22:52:08 1988
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f CONFIG.H -a "${1}" != "-c" ; then 
  37.   echo shar: Will not over-write existing file \"CONFIG.H\"
  38. else
  39. echo shar: Extracting \"CONFIG.H\" \(3394 characters\)
  40. sed "s/^X//" >CONFIG.H <<'END_OF_CONFIG.H'
  41. X/* GNU Emacs site configuration template file.
  42. X   Copyright (C) 1986 Free Software Foundation, Inc.
  43. X
  44. XThis file is part of GNU Emacs.
  45. X
  46. XGNU Emacs is distributed in the hope that it will be useful,
  47. Xbut WITHOUT ANY WARRANTY.  No author or distributor
  48. Xaccepts responsibility to anyone for the consequences of using it
  49. Xor for whether it serves any particular purpose or works at all,
  50. Xunless he says so in writing.  Refer to the GNU Emacs General Public
  51. XLicense for full details.
  52. X
  53. XEveryone is granted permission to copy, modify and redistribute
  54. XGNU Emacs, but only under the conditions described in the
  55. XGNU Emacs General Public License.   A copy of this license is
  56. Xsupposed to have been given to you along with GNU Emacs so you
  57. Xcan know your rights and responsibilities.  It should be in a
  58. Xfile named COPYING.  Among other things, the copyright notice
  59. Xand this notice must be preserved on all copies.  */
  60. X
  61. X
  62. X
  63. X/* Include here a s- file that describes the system type you are using.
  64. X   See the file ../etc/MACHINES for a list of systems and
  65. X   the names of the s- files to use for them.
  66. X   See s-template.h for documentation on writing s- files.  */
  67. X/* #include "s-vms4-4.h" */
  68. X/* Include here a m- file that describes the machine and system you use.
  69. X   See the file ../etc/MACHINES for a list of machines and
  70. X   the names of the m- files to use for them.
  71. X   See m-template.h for info on what m- files should define.
  72. X   */
  73. X/* #include "m-vax.h" */
  74. X
  75. X/* Load in the conversion definitions if this system
  76. X   needs them and the source file being compiled has not
  77. X   said to inhibit this.  */
  78. X
  79. X#ifdef SHORTNAMES
  80. X#ifndef NO_SHORTNAMES
  81. X#include "../shortnames/remap.h"
  82. X#endif /* not NO_SHORTNAMES */
  83. X#endif /* SHORTNAMES */
  84. X
  85. X/* define HAVE_X_WINDOWS if you want to use the X window system */
  86. X
  87. X/* #define HAVE_X_WINDOWS */
  88. X
  89. X/* define HAVE_X_MENU if you want to use the X window menu system.
  90. X   This appears to work on some machines that support X
  91. X   and not on others.  */
  92. X
  93. X/* #define HAVE_X_MENU */
  94. X
  95. X/* subprocesses should be defined if you want to
  96. X have code for asynchronous subprocesses
  97. X (as used in M-x compile and M-x shell).
  98. X These do not work for some USG systems yet;
  99. X for the ones where they work, the s-*.h file defines this flag.  */
  100. X
  101. X/* 
  102. X#ifndef VMS
  103. X#ifndef USG
  104. X#define subprocesses
  105. X#endif
  106. X#endif
  107. X */
  108. X
  109. X/* Define USER_FULL_NAME to return a string
  110. X that is the user's full name.
  111. X It can assume that the variable `pw'
  112. X points to the password file entry for this user.
  113. X
  114. X At some sites, the pw_gecos field contains
  115. X the user's full name.  If neither this nor any other
  116. X field contains the right thing, use pw_name,
  117. X giving the user's login name, since that is better than nothing.  */
  118. X
  119. X#define USER_FULL_NAME pw->pw_gecos
  120. X
  121. X/* Define AMPERSAND_FULL_NAME if you use the convention
  122. X  that & in the full name stands for the login id.  */
  123. X
  124. X/* #define AMPERSAND_FULL_NAME */
  125. X
  126. X/* Maximum screen width we handle. */
  127. X
  128. X#define MScreenWidth 300
  129. X
  130. X/* Maximum screen length we handle. */
  131. X
  132. X#define MScreenLength 300
  133. X
  134. X/* # bytes of pure Lisp code to leave space for.
  135. X  s-vms.h and m-sun2.h can override this default.  */
  136. X
  137. X#ifndef PURESIZE
  138. X#ifdef HAVE_X_WINDOWS
  139. X#define PURESIZE 120000
  140. X#else
  141. X#define PURESIZE 115800
  142. X#endif
  143. X#endif
  144. X
  145. X/* Define HIGHPRI as a negative number
  146. X if you want Emacs to run at a higher than normal priority.
  147. X For this to take effect, you must install it as setuid root. */
  148. X
  149. X/* #define HIGHPRI */
  150. X
  151. END_OF_CONFIG.H
  152. if test 3394 -ne `wc -c <CONFIG.H`; then
  153.     echo shar: \"CONFIG.H\" unpacked with wrong size!
  154. fi
  155. # end of overwriting check
  156. fi
  157. if test -f FILES.LS -a "${1}" != "-c" ; then 
  158.   echo shar: Will not over-write existing file \"FILES.LS\"
  159. else
  160. echo shar: Extracting \"FILES.LS\" \(520 characters\)
  161. sed "s/^X//" >FILES.LS <<'END_OF_FILES.LS'
  162. Xtotal 88
  163. X-rw-rw-r--   1 bin      staff       3394 Mar 19 11:08 config.h
  164. X-rw-r--r--   1 shields  staff          0 Apr 20 23:31 files.ls
  165. X-rw-rw-r--   1 bin      staff        996 Apr 20 23:30 makefile.lc
  166. X-rw-rw-r--   1 bin      staff        399 Apr 20 23:29 makefile.sco
  167. X-rw-rw-r--   1 bin      staff        159 Mar 19 11:07 mk.bat
  168. X-rw-rw-r--   1 bin      staff      18812 Mar 21 22:50 termcap.c
  169. X-rw-rw-r--   1 bin      staff       5113 Mar 19 11:09 textern.c
  170. X-rw-rw-r--   1 bin      staff      11046 Mar 21 22:39 tparam.c
  171. END_OF_FILES.LS
  172. if test 520 -ne `wc -c <FILES.LS`; then
  173.     echo shar: \"FILES.LS\" unpacked with wrong size!
  174. fi
  175. # end of overwriting check
  176. fi
  177. if test -f MAKEFILE.LC -a "${1}" != "-c" ; then 
  178.   echo shar: Will not over-write existing file \"MAKEFILE.LC\"
  179. else
  180. echo shar: Extracting \"MAKEFILE.LC\" \(996 characters\)
  181. sed "s/^X//" >MAKEFILE.LC <<'END_OF_MAKEFILE.LC'
  182. X# Lattice C Makefile for termcap library.
  183. X# 
  184. X# Note: This version of termcap is from GNU emacs. See the .c source
  185. X#       files for a note on the license. 
  186. X
  187. XDEBUG  = -d
  188. XTEST   =
  189. XMODEL  = s
  190. XCC     = lc
  191. XCFLAGS = -m$(MODEL) -n -cws -o.\ -i.. -R$(MODEL)termcap $(DEBUG) $(TEST)
  192. X
  193. Xall: $(MODEL)termcap.lib
  194. X
  195. Xstermcap.lib: termcap.obj tparam.obj textern.obj
  196. X    oml $(MODEL)termcap l >$(MODEL)termcap.lst
  197. X    copy $(MODEL)termcap.lib /usr/lib
  198. X
  199. Xptermcap.lib: termcap.obj tparam.obj textern.obj
  200. X    oml $(MODEL)termcap l >$(MODEL)termcap.lst
  201. X    copy $(MODEL)termcap.lib /usr/lib
  202. X
  203. Xdtermcap.lib: termcap.obj tparam.obj textern.obj
  204. X    oml $(MODEL)termcap l >$(MODEL)termcap.lst
  205. X    copy $(MODEL)termcap.lib /usr/lib
  206. X
  207. Xltermcap.lib: termcap.obj tparam.obj textern.obj
  208. X    oml $(MODEL)termcap l >$(MODEL)termcap.lst
  209. X    copy $(MODEL)termcap.lib /usr/lib
  210. X
  211. Xtermcap.obj:    ../termcap.c
  212. X    $(CC) $(CFLAGS) ../termcap.c
  213. X
  214. Xtparam.obj:     ../tparam.c
  215. X    $(CC) $(CFLAGS) ../tparam.c
  216. X
  217. Xtextern.obj:     ../textern.c
  218. X    $(CC) $(CFLAGS) ../textern.c
  219. X
  220. END_OF_MAKEFILE.LC
  221. if test 996 -ne `wc -c <MAKEFILE.LC`; then
  222.     echo shar: \"MAKEFILE.LC\" unpacked with wrong size!
  223. fi
  224. # end of overwriting check
  225. fi
  226. if test -f MAKEFILE.SCO -a "${1}" != "-c" ; then 
  227.   echo shar: Will not over-write existing file \"MAKEFILE.SCO\"
  228. else
  229. echo shar: Extracting \"MAKEFILE.SCO\" \(399 characters\)
  230. sed "s/^X//" >MAKEFILE.SCO <<'END_OF_MAKEFILE.SCO'
  231. X# SCO Xenix Makefile for termcap library.
  232. X# 
  233. X# Note: This version of termcap is from GNU emacs. See the .c source
  234. X#       files for a note on the license. 
  235. X
  236. XDEBUG  = -d
  237. XTEST   =
  238. XCFLAGS = -DSYSV
  239. X
  240. Xall: termcap.obj tparam.obj textern.obj
  241. X
  242. Xtermcap.obj:    termcap.c  
  243. X    cc $(CFLAGS) termcap.c -c
  244. X
  245. Xtparam.obj:     tparam.c 
  246. X    cc $(CFLAGS) tparam.c -c
  247. X
  248. Xtextern.obj:    textern.c 
  249. X    cc $(CFLAGS) textern.c -c
  250. END_OF_MAKEFILE.SCO
  251. if test 399 -ne `wc -c <MAKEFILE.SCO`; then
  252.     echo shar: \"MAKEFILE.SCO\" unpacked with wrong size!
  253. fi
  254. # end of overwriting check
  255. fi
  256. if test -f MK.BAT -a "${1}" != "-c" ; then 
  257.   echo shar: Will not over-write existing file \"MK.BAT\"
  258. else
  259. echo shar: Extracting \"MK.BAT\" \(159 characters\)
  260. sed "s/^X//" >MK.BAT <<'END_OF_MK.BAT'
  261. Xif .%1 == . goto usage
  262. X:top
  263. Xcd %1
  264. Xmake -f ../Makefile.lc "MODEL=%1" >make.err
  265. Xcd ..
  266. Xshift
  267. Xif .%1 == . goto end
  268. Xgoto top
  269. X:usage
  270. Xecho    usage:  mk s p d l
  271. X:end
  272. END_OF_MK.BAT
  273. if test 159 -ne `wc -c <MK.BAT`; then
  274.     echo shar: \"MK.BAT\" unpacked with wrong size!
  275. fi
  276. chmod +x MK.BAT
  277. # end of overwriting check
  278. fi
  279. if test -f TERMCAP.C -a "${1}" != "-c" ; then 
  280.   echo shar: Will not over-write existing file \"TERMCAP.C\"
  281. else
  282. echo shar: Extracting \"TERMCAP.C\" \(18812 characters\)
  283. sed "s/^X//" >TERMCAP.C <<'END_OF_TERMCAP.C'
  284. X/* Work-alike for termcap, plus extra features.
  285. X   Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  286. X
  287. X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
  288. X   Dec 1987 - Mar 1988.
  289. X
  290. X               NO WARRANTY
  291. X
  292. X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  293. XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  294. XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  295. XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  296. XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  297. XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  298. XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  299. XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  300. XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  301. XCORRECTION.
  302. X
  303. X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  304. XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  305. XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  306. XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  307. XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  308. XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  309. XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  310. XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  311. XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  312. XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  313. X
  314. X        GENERAL PUBLIC LICENSE TO COPY
  315. X
  316. X   1. You may copy and distribute verbatim copies of this source file
  317. Xas you receive it, in any medium, provided that you conspicuously and
  318. Xappropriately publish on each copy a valid copyright notice "Copyright
  319. X(C) 1986 Free Software Foundation, Inc."; and include following the
  320. Xcopyright notice a verbatim copy of the above disclaimer of warranty
  321. Xand of this License.  You may charge a distribution fee for the
  322. Xphysical act of transferring a copy.
  323. X
  324. X   2. You may modify your copy or copies of this source file or
  325. Xany portion of it, and copy and distribute such modifications under
  326. Xthe terms of Paragraph 1 above, provided that you also do the following:
  327. X
  328. X      a) cause the modified files to carry prominent notices stating
  329. X      that you changed the files and the date of any change; and
  330. X
  331. X      b) cause the whole of any work that you distribute or publish,
  332. X      that in whole or in part contains or is a derivative of this
  333. X      program or any part thereof, to be licensed at no charge to all
  334. X      third parties on terms identical to those contained in this
  335. X      License Agreement (except that you may choose to grant more
  336. X      extensive warranty protection to third parties, at your option).
  337. X
  338. X      c) You may charge a distribution fee for the physical act of
  339. X      transferring a copy, and you may at your option offer warranty
  340. X      protection in exchange for a fee.
  341. X
  342. X    3. You may copy and distribute this program or any portion of it in
  343. Xcompiled, executable or object code form under the terms of Paragraphs
  344. X1 and 2 above provided that you do the following:
  345. X
  346. X      a) cause each such copy to be accompanied by the
  347. X      corresponding machine-readable source code, which must
  348. X      be distributed under the terms of Paragraphs 1 and 2 above; or,
  349. X
  350. X      b) cause each such copy to be accompanied by a
  351. X      written offer, with no time limit, to give any third party
  352. X      free (except for a nominal shipping charge) a machine readable
  353. X      copy of the corresponding source code, to be distributed
  354. X      under the terms of Paragraphs 1 and 2 above; or,
  355. X
  356. X      c) in the case of a recipient of this program in compiled, executable
  357. X      or object code form (without the corresponding source code) you
  358. X      shall cause copies you distribute to be accompanied by a copy
  359. X      of the written offer of source code which you received along
  360. X      with the copy you received.
  361. X
  362. X    4. You may not copy, sublicense, distribute or transfer this program
  363. Xexcept as expressly provided under this License Agreement.  Any attempt
  364. Xotherwise to copy, sublicense, distribute or transfer this program is void and
  365. Xyour rights to use the program under this License agreement shall be
  366. Xautomatically terminated.  However, parties who have received computer
  367. Xsoftware programs from you with this License Agreement will not have
  368. Xtheir licenses terminated so long as such parties remain in full compliance.
  369. X
  370. X    5. If you wish to incorporate parts of this program into other free
  371. Xprograms whose distribution conditions are different, write to the Free
  372. XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
  373. Xworked out a simple rule that can be stated here, but we will often permit
  374. Xthis.  We will be guided by the two goals of preserving the free status of
  375. Xall derivatives of our free software and of promoting the sharing and reuse of
  376. Xsoftware.
  377. X
  378. X
  379. XIn other words, you are welcome to use, share and improve this program.
  380. XYou are forbidden to forbid anyone else to use, share and improve
  381. Xwhat you give them.   Help stamp out software-hoarding!  */
  382. X
  383. X
  384. X
  385. X/* BUFSIZE is the initial size allocated for the buffer
  386. X   for reading the termcap file.
  387. X   It is not a limit.
  388. X   Make it large normally for speed.
  389. X   Make it variable when debugging, so can exercise
  390. X   increasing the space dynamically.  */
  391. X
  392. X#ifdef emacs
  393. X#include "config.h"
  394. X#else
  395. X#include <fcntl.h>
  396. X#endif
  397. X
  398. X/* MODS for MS-DOS by Paul Shields, December 1987. */
  399. X#ifdef MSDOS
  400. X#include <stdlib.h>
  401. X#endif
  402. X
  403. X#if defined(MSDOS) || defined(SYSV)
  404. X#define  bcopy(b,a,n) memcpy(a,b,n)
  405. X#endif
  406. X
  407. X#ifndef BUFSIZE
  408. X# ifdef DEBUG
  409. X#  include <stdio.h>
  410. X#  define  BUFSIZE bufsize
  411. X   int bufsize = 2048;
  412. X   extern int  debuglevel;
  413. X# else
  414. X#  define BUFSIZE 2048
  415. X# endif
  416. X#endif
  417. X
  418. X#ifndef emacs
  419. Xstatic void
  420. Xmemory_out ()
  421. X{
  422. X    write (2, "memory exhausted\n", 25);
  423. X    exit (1);
  424. X}
  425. X
  426. Xstatic char *
  427. Xxmalloc (size)
  428. X       int size;
  429. X{
  430. X    register char *tem = malloc (size);
  431. X    if (!tem)
  432. X        memory_out ();
  433. X    return tem;
  434. X}
  435. X
  436. Xstatic char *
  437. Xxrealloc (ptr, size)
  438. X       int ptr;
  439. X       int size;
  440. X{
  441. X    register char *tem = realloc (ptr, size);
  442. X    if (!tem)
  443. X        memory_out ();
  444. X    return tem;
  445. X}
  446. X#endif /* not emacs */
  447. X
  448. X/* Looking up capabilities in the entry already found */
  449. X
  450. X/* The pointer to the data made by tgetent is left here
  451. X     for tgetnum, tgetflag and tgetstr to find.  */
  452. X
  453. Xstatic char *term_entry;
  454. X
  455. Xstatic char *tgetst1 ();
  456. X
  457. X/* This is the main subroutine that is used to search
  458. X     an entry for a particular capability */
  459. X
  460. Xstatic char *
  461. Xfind_capability (bp, cap)
  462. X       register char *bp, *cap;
  463. X{
  464. X    for (; *bp; bp++)
  465. X        if (bp[0] == ':' && bp[1] == cap[0] && bp[2] == cap[1])
  466. X            return &bp[4];
  467. X    return 0;
  468. X}
  469. X
  470. Xint
  471. Xtgetnum (cap)
  472. X       char *cap;
  473. X{
  474. X    register char *ptr = find_capability (term_entry, cap);
  475. X#ifdef DEBUG
  476. X    if(debuglevel & 4)
  477. X        fprintf(stderr,"cap: %s, num: %d\n", cap, atoi(ptr));
  478. X#endif
  479. X    if (!ptr || ptr[-1] != '#')
  480. X        return -1;
  481. X    return atoi (ptr);
  482. X}
  483. X
  484. Xint
  485. Xtgetflag (cap)
  486. X       char *cap;
  487. X{
  488. X    register char *ptr = find_capability (term_entry, cap);
  489. X    return 0 != ptr && ptr[-1] == ':';
  490. X}
  491. X
  492. X/* Look up a string-valued capability `cap'.
  493. X     If `area' is nonzero, it points to a pointer to a block in which
  494. X     to store the string.  That pointer is advanced over the space used.
  495. X     If `area' is zero, space is allocated with `malloc'.  */
  496. X
  497. Xchar *
  498. Xtgetstr (cap, area)
  499. X       char *cap;
  500. X       char **area;
  501. X{
  502. X    register char *ptr = find_capability (term_entry, cap);
  503. X    if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~'))
  504. X        return 0;
  505. X    return tgetst1 (ptr, area);
  506. X}
  507. X
  508. X/* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted,
  509. X   gives meaning of character following \, or a space if no special meaning.
  510. X   Eight characters per line within the string.  */
  511. X
  512. Xstatic char esctab[] = "\
  513. X\040\007\010\040\040\033\014\040\
  514. X\040\040\040\040\040\040\012\040\
  515. X\040\040\015\040\011\040\013\040\
  516. X\040\040\040\040\040\040\040\040";
  517. X
  518. X/* Given a pointer to a string value inside a termcap entry (`ptr'),
  519. X   copy the value and process \ and ^ abbreviations.
  520. X   Copy into block that *area points to,
  521. X   or to newly allocated storage if area is 0.  */
  522. X
  523. Xstatic char *
  524. Xtgetst1 (ptr, area)
  525. X       char *ptr;
  526. X       char **area;
  527. X{
  528. X    register char *p, *r;
  529. X    register int c;
  530. X    register int size;
  531. X    char *ret;
  532. X    register int c1;
  533. X
  534. X    if (!ptr)
  535. X      return 0;
  536. X
  537. X    /* `ret' gets address of where to store the string */
  538. X    if (!area)
  539. X      {
  540. X        /* Compute size of block needed (may overestimate) */
  541. X        p = ptr;
  542. X        while ((c = *p++) && c != ':');
  543. X        ret = xmalloc (p - ptr + 1);
  544. X      }
  545. X    else
  546. X      ret = *area;
  547. X
  548. X    /* Copy the string value, stopping at null or colon.  */
  549. X    /* Also process ^ and \ abbreviations.  */
  550. X    p = ptr;
  551. X    r = ret;
  552. X    while ((c = *p++) && c != ':')
  553. X      {
  554. X        if (c == '^')
  555. X    c = *p++ & 037;
  556. X        else if (c == '\\')
  557. X    {
  558. X      c = *p++;
  559. X      if (c >= '0' && c <= '7')
  560. X        {
  561. X          c -= '0';
  562. X          size = 0;
  563. X
  564. X          while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7')
  565. X        {
  566. X          c *= 8;
  567. X          c += c1 - '0';
  568. X          p++;
  569. X        }
  570. X        }
  571. X      else if (c >= 0100 && c < 0200)
  572. X        {
  573. X          c1 = esctab[(c & ~040) - 0100];
  574. X          if (c1 != ' ')
  575. X        c = c1;
  576. X        }
  577. X    }
  578. X        *r++ = c;
  579. X      }
  580. X    *r = 0;
  581. X    /* Update *area */
  582. X    if (area)
  583. X      *area = r + 1;
  584. X    return ret;
  585. X}
  586. X
  587. X/* Outputting a string with padding */
  588. Xextern short ospeed;
  589. Xextern char PC;
  590. X
  591. X/* Actual baud rate if positive;
  592. X     - baud rate / 100 if negative.  */
  593. X
  594. Xstatic short speeds[] =
  595. X    {
  596. X#ifdef VMS
  597. X      0, 50, 75, 110, 134, 150, -3, -6, -12, -18,
  598. X      -20, -24, -36, -48, -72, -96, -192
  599. X#else /* not VMS */
  600. X      0, 50, 75, 110, 135, 150, -2, -3, -6, -12,
  601. X      -18, -24, -48, -96, -192, -384
  602. X#endif /* not VMS */
  603. X    };
  604. X
  605. Xvoid
  606. Xtputs (string, nlines, outfun)
  607. X       register char *string;
  608. X       int nlines;
  609. X       register int (*outfun) ();
  610. X{
  611. X    register int padcount = 0;
  612. X
  613. X    if (string == (char *) 0)
  614. X      return;
  615. X    while (*string >= '0' && *string <= '9')
  616. X      {
  617. X        padcount += *string++ - '0';
  618. X        padcount *= 10;
  619. X      }
  620. X    if (*string == '.')
  621. X      {
  622. X        string++;
  623. X        padcount += *string++ - '0';
  624. X      }
  625. X    if (*string == '*')
  626. X      {
  627. X        string++;
  628. X        padcount *= nlines;
  629. X      }
  630. X    while (*string)
  631. X      (*outfun) (*string++);
  632. X
  633. X    /* padcount is now in units of tenths of msec.  */
  634. X    padcount *= speeds[ospeed];
  635. X    padcount += 500;
  636. X    padcount /= 1000;
  637. X    if (speeds[ospeed] < 0)
  638. X      padcount = -padcount;
  639. X    else
  640. X      {
  641. X        padcount += 50;
  642. X        padcount /= 100;
  643. X      }
  644. X
  645. X    while (padcount-- > 0)
  646. X      (*outfun) (PC);
  647. X}
  648. X
  649. X/* Finding the termcap entry in the termcap data base */
  650. X
  651. Xstruct buffer
  652. X    {
  653. X      char *beg;
  654. X      int size;
  655. X      char *ptr;
  656. X      int ateof;
  657. X      int full;
  658. X    };
  659. X
  660. X/* Forward declarations of static functions */
  661. X
  662. Xstatic int scan_file ();
  663. Xstatic char *gobble_line ();
  664. Xstatic int compare_contin ();
  665. Xstatic int name_match ();
  666. X
  667. X#ifdef VMS
  668. X
  669. X#include <rmsdef.h>
  670. X#include <fab.h>
  671. X#include <nam.h>
  672. X
  673. Xstatic int
  674. Xlegal_filename_p (fn)
  675. X       char *fn;
  676. X{
  677. X    struct FAB fab = cc$rms_fab;
  678. X    struct NAM nam = cc$rms_nam;
  679. X    char esa[NAM$C_MAXRSS];
  680. X
  681. X    fab.fab$l_fna = fn;
  682. X    fab.fab$b_fns = strlen(fn);
  683. X    fab.fab$l_nam = &nam;
  684. X    fab.fab$l_fop = FAB$M_NAM;
  685. X
  686. X    nam.nam$l_esa = esa;
  687. X    nam.nam$b_ess = sizeof esa;
  688. X
  689. X    return SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL;
  690. X}
  691. X
  692. X#endif /* VMS */
  693. X
  694. X/* Find the termcap entry data for terminal type `name'
  695. X     and store it in the block that `bp' points to.
  696. X     Record its address for future use.
  697. X
  698. X     If `bp' is zero, space is dynamically allocated.  */
  699. X
  700. Xint
  701. Xtgetent (bp, name)
  702. X       char *bp, *name;
  703. X{
  704. X    register char *tem;
  705. X    register int fd;
  706. X    struct buffer buf;
  707. X    register char *bp1;
  708. X    char *bp2;
  709. X    char *term;
  710. X    int malloc_size = 0;
  711. X    register int c;
  712. X    char *tcenv;            /* TERMCAP value, if it contains :tc=.  */
  713. X    char *indirect = 0;        /* Terminal type in :tc= in TERMCAP value.  */
  714. X    int filep;
  715. X
  716. X#ifdef DEBUG
  717. X    if(debuglevel & 4)
  718. X        fprintf(stderr,"tgetent(buf, %s)\n", name);
  719. X#endif
  720. X
  721. X    tem = (char *) getenv ("TERMCAP");
  722. X    if (tem && *tem == 0) tem = 0;
  723. X
  724. X#ifdef VMS
  725. X    filep = (tem && legal_filename_p (tem));
  726. X#else
  727. X    filep = (tem && (*tem == '/'));
  728. X#endif /* VMS */
  729. X
  730. X    /* If tem is non-null and starts with / (in the un*x case, that is),
  731. X       it is a file name to use instead of /etc/termcap.
  732. X       If it is non-null and does not start with /,
  733. X       it is the entry itself, but only if
  734. X       the name the caller requested matches the TERM variable.  */
  735. X
  736. X    if (tem && !filep && !strcmp (name, getenv ("TERM")))
  737. X     {
  738. X        indirect = tgetst1 (find_capability (tem, "tc"), 0);
  739. X        if (!indirect)
  740. X           {
  741. X           if (!bp)
  742. X             bp = tem;
  743. X           else
  744. X             strcpy (bp, tem);
  745. X           goto ret;
  746. X         }
  747. X        else
  748. X         {            /* we will need to read /etc/termcap */
  749. X           tcenv = tem;
  750. X           tem = 0;
  751. X         }
  752. X     }
  753. X    else
  754. X        indirect = (char *) 0;
  755. X
  756. X    if (!tem)
  757. X#ifdef VMS
  758. X      tem = "emacs_library:[etc]termcap.dat";
  759. X#else
  760. X      tem = "/etc/termcap";
  761. X#endif
  762. X
  763. X    /* Here we know we must search a file and tem has its name.  */
  764. X
  765. X#ifdef DEBUG
  766. X    if(debuglevel & 4)
  767. X        fprintf(stderr,"%s: ", tem);
  768. X#endif
  769. X    fd = open (tem, 0, 0);
  770. X    if (fd < 0)
  771. X      return -1;
  772. X
  773. X    buf.size = BUFSIZE;
  774. X    buf.beg = xmalloc (buf.size);
  775. X    term = indirect ? indirect : name;
  776. X
  777. X#ifdef DEBUG
  778. X    if(debuglevel & 4)
  779. X        fprintf(stderr,"...opened\n");
  780. X#endif
  781. X    if (!bp)
  782. X      {
  783. X        malloc_size = indirect ? strlen (tcenv) + 1 : buf.size;
  784. X        bp = xmalloc (malloc_size);
  785. X      }
  786. X    bp1 = bp;
  787. X
  788. X    if (indirect)            /* copy the data from the environment variable */
  789. X      {
  790. X        strcpy (bp, tcenv);
  791. X        bp1 += strlen (tcenv);
  792. X      }
  793. X
  794. X    while (term)
  795. X      {
  796. X#ifdef DEBUG
  797. X    if(debuglevel & 4)
  798. X        fprintf(stderr,"term = %s\n", term);
  799. X#endif
  800. X        /* Scan file, reading it via buf, till find start of main entry */
  801. X        if (scan_file (term, fd, &buf) == 0)
  802. X            return 0;
  803. X
  804. X        /* Free old `term' if appropriate.  */
  805. X        if (term != name)
  806. X            free (term);
  807. X
  808. X        /* If `bp' is malloc'd by us, make sure it is big enough.  */
  809. X        if (malloc_size)
  810. X         {
  811. X            malloc_size = bp1 - bp + buf.size;
  812. X            tem = xrealloc (bp, malloc_size);
  813. X            bp1 += tem - bp;
  814. X            bp = tem;
  815. X         }
  816. X
  817. X        bp2 = bp1;
  818. X
  819. X        /* Copy the line of the entry from buf into bp.  */
  820. X        tem = buf.ptr;
  821. X        while ((*bp1++ = c = *tem++) && c != '\n') {
  822. X            /* Drop out any \ newline sequence, and following whitespace */
  823. X            if (c == '\\' && *tem == '\n')
  824. X             {
  825. X                bp1--;
  826. X                tem++;
  827. X                while ((c = *tem++) == ' ' || c == '\t')
  828. X                    ;
  829. X                tem--;
  830. X             }
  831. X        }
  832. X        *bp1 = 0;
  833. X
  834. X        /* Does this entry refer to another terminal type's entry?  */
  835. X        /* If something is found, copy it into heap and null-terminate it */
  836. X        term = tgetst1 (find_capability (bp2, "tc"), 0);
  837. X      }
  838. X
  839. X    close (fd);
  840. X    free (buf.beg);
  841. X
  842. X    if (malloc_size)
  843. X      {
  844. X        bp = xrealloc (bp, bp1 - bp + 1);
  845. X      }
  846. X
  847. X ret:
  848. X    term_entry = bp;
  849. X
  850. X#ifdef DEBUG
  851. X    if(debuglevel & 4)
  852. X        fprintf(stderr,"term_entry = %s\n", term_entry);
  853. X#endif
  854. X    if (malloc_size)
  855. X      return (int) bp;
  856. X    return 1;
  857. X}
  858. X
  859. X/* Given file open on `fd' and buffer `bufp',
  860. X   scan the file from the beginning until a line is found
  861. X   that starts the entry for terminal type `string'.
  862. X   Returns 1 if successful, with that line in `bufp',
  863. X   or returns 0 if no entry found in the file.  */
  864. X
  865. Xstatic int
  866. Xscan_file (string, fd, bufp)
  867. X       char *string;
  868. X       int fd;
  869. X       register struct buffer *bufp;
  870. X{
  871. X    register char *end;
  872. X
  873. X    bufp->ptr = bufp->beg;
  874. X    bufp->full = 0;
  875. X    bufp->ateof = 0;
  876. X    *bufp->ptr = 0;
  877. X
  878. X    lseek (fd, 0L, 0);
  879. X
  880. X    while (!bufp->ateof)
  881. X      {
  882. X        /* Read a line into the buffer */
  883. X        end = 0;
  884. X        do
  885. X    {
  886. X      /* if it is continued, append another line to it,
  887. X         until a non-continued line ends */
  888. X      end = gobble_line (fd, bufp, end);
  889. X    }
  890. X        while (!bufp->ateof && end[-2] == '\\');
  891. X
  892. X        if (*bufp->ptr != '#'
  893. X      && name_match (bufp->ptr, string))
  894. X    return 1;
  895. X
  896. X        /* Discard the line just processed */
  897. X        bufp->ptr = end;
  898. X      }
  899. X    return 0;
  900. X}
  901. X
  902. X/* Return nonzero if NAME is one of the names specified
  903. X     by termcap entry LINE.  */
  904. X
  905. Xstatic int
  906. Xname_match (line, name)
  907. X       char *line, *name;
  908. X{
  909. X    register char *tem;
  910. X
  911. X    if (!compare_contin (line, name))
  912. X      return 1;
  913. X    /* This line starts an entry.  Is it the right one?  */
  914. X    for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++)
  915. X      if (*tem == '|' && !compare_contin (tem + 1, name))
  916. X        return 1;
  917. X
  918. X    return 0;
  919. X}
  920. X
  921. Xstatic int
  922. Xcompare_contin (str1, str2)
  923. X       register char *str1, *str2;
  924. X{
  925. X    register int c1, c2;
  926. X    while (1)
  927. X      {
  928. X        c1 = *str1++;
  929. X        c2 = *str2++;
  930. X        while (c1 == '\\' && *str1 == '\n')
  931. X    {
  932. X      str1++;
  933. X      while ((c1 = *str1++) == ' ' || c1 == '\t');
  934. X    }
  935. X        if (c2 == '\0')        /* end of type being looked up */
  936. X    {
  937. X      if (c1 == '|' || c1 == ':') /* If end of name in data base, */
  938. X        return 0;        /* we win. */
  939. X      else
  940. X        return 1;
  941. X          }
  942. X        else if (c1 != c2)
  943. X    return 1;
  944. X      }
  945. X}
  946. X
  947. X/* Make sure that the buffer <- `bufp' contains a full line
  948. X     of the file open on `fd', starting at the place `bufp->ptr'
  949. X     points to.  Can read more of the file, discard stuff before
  950. X     `bufp->ptr', or make the buffer bigger.
  951. X
  952. X     Returns the pointer to after the newline ending the line,
  953. X     or to the end of the file, if there is no newline to end it.
  954. X
  955. X     Can also merge on continuation lines.  If `append_end' is
  956. X     nonzero, it points past the newline of a line that is
  957. X     continued; we add another line onto it and regard the whole
  958. X     thing as one line.  The caller decides when a line is continued.  */
  959. X
  960. Xstatic char *
  961. Xgobble_line (fd, bufp, append_end)
  962. X       int fd;
  963. X       register struct buffer *bufp;
  964. X       char *append_end;
  965. X{
  966. X    register char *end;
  967. X    register int nread;
  968. X    register char *buf = bufp->beg;
  969. X    register char *tem;
  970. X
  971. X    if (append_end == 0)
  972. X      append_end = bufp->ptr;
  973. X
  974. X    while (1)
  975. X      {
  976. X        end = append_end;
  977. X        while (*end && *end != '\n') end++;
  978. X        if (*end)
  979. X          break;
  980. X        if (bufp->ateof)
  981. X    return buf + bufp->full;
  982. X        if (bufp->ptr == buf)
  983. X    {
  984. X      if (bufp->full == bufp->size)
  985. X        {
  986. X          bufp->size *= 2;
  987. X          tem = xrealloc (buf, bufp->size);
  988. X          bufp->ptr += tem - buf;
  989. X          append_end += tem - buf;
  990. X          bufp->beg = buf = tem;
  991. X        }
  992. X    }
  993. X        else
  994. X    {
  995. X      append_end -= bufp->ptr - buf;
  996. X      bcopy (bufp->ptr, buf, bufp->full -= bufp->ptr - buf);
  997. X      bufp->ptr = buf;
  998. X    }
  999. X        if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full)))
  1000. X    bufp->ateof = 1;
  1001. X        bufp->full += nread;
  1002. X        if (bufp->full != bufp->size)
  1003. X    buf[bufp->full] = 0;
  1004. X      }
  1005. X    return end + 1;
  1006. X}
  1007. X
  1008. X#ifdef TEST
  1009. X#include <stdio.h>
  1010. X
  1011. Xmain (argc, argv)
  1012. X       int argc;
  1013. X       char **argv;
  1014. X{
  1015. X    char *term;
  1016. X    char *buf;
  1017. X
  1018. X    term = argv[1];
  1019. X    printf ("TERM: %s\n", term);
  1020. X
  1021. X    buf = (char *) tgetent (0, term);
  1022. X    if ((int) buf <= 0)
  1023. X      {
  1024. X        printf ("No entry.\n");
  1025. X        return 0;
  1026. X      }
  1027. X
  1028. X    printf ("Entry: %s\n", buf);
  1029. X
  1030. X    tprint ("cm");
  1031. X    tprint ("AL");
  1032. X
  1033. X    printf ("co: %d\n", tgetnum ("co"));
  1034. X    printf ("am: %d\n", tgetflag ("am"));
  1035. X}
  1036. X
  1037. Xtprint (cap)
  1038. X       char *cap;
  1039. X{
  1040. X    char *x = tgetstr (cap, 0);
  1041. X    register char *y;
  1042. X
  1043. X    printf ("%s: ", cap);
  1044. X    if (x)
  1045. X      {
  1046. X        for (y = x; *y; y++)
  1047. X    if (*y <= ' ' || *y == 0177)
  1048. X      printf ("\\%0o", *y);
  1049. X    else
  1050. X      putchar (*y);
  1051. X        free (x);
  1052. X      }
  1053. X    else
  1054. X      printf ("none");
  1055. X    putchar ('\n');
  1056. X}
  1057. X
  1058. X#endif /* TEST */
  1059. END_OF_TERMCAP.C
  1060. if test 18812 -ne `wc -c <TERMCAP.C`; then
  1061.     echo shar: \"TERMCAP.C\" unpacked with wrong size!
  1062. fi
  1063. # end of overwriting check
  1064. fi
  1065. if test -f TEXTERN.C -a "${1}" != "-c" ; then 
  1066.   echo shar: Will not over-write existing file \"TEXTERN.C\"
  1067. else
  1068. echo shar: Extracting \"TEXTERN.C\" \(5113 characters\)
  1069. sed "s/^X//" >TEXTERN.C <<'END_OF_TEXTERN.C'
  1070. X/* Termcap External Variables.
  1071. X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  1072. X
  1073. X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
  1074. X   Dec 1987 - Mar 1988.
  1075. X
  1076. X               NO WARRANTY
  1077. X
  1078. X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  1079. XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  1080. XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  1081. XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  1082. XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  1083. XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1084. XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  1085. XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  1086. XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  1087. XCORRECTION.
  1088. X
  1089. X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  1090. XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  1091. XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  1092. XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  1093. XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  1094. XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  1095. XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  1096. XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  1097. XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  1098. XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  1099. X
  1100. X        GENERAL PUBLIC LICENSE TO COPY
  1101. X
  1102. X  1. You may copy and distribute verbatim copies of this source file
  1103. Xas you receive it, in any medium, provided that you conspicuously and
  1104. Xappropriately publish on each copy a valid copyright notice "Copyright
  1105. X(C) 1986 Free Software Foundation, Inc."; and include following the
  1106. Xcopyright notice a verbatim copy of the above disclaimer of warranty
  1107. Xand of this License.  You may charge a distribution fee for the
  1108. Xphysical act of transferring a copy.
  1109. X
  1110. X  2. You may modify your copy or copies of this source file or
  1111. Xany portion of it, and copy and distribute such modifications under
  1112. Xthe terms of Paragraph 1 above, provided that you also do the following:
  1113. X
  1114. X    a) cause the modified files to carry prominent notices stating
  1115. X    that you changed the files and the date of any change; and
  1116. X
  1117. X    b) cause the whole of any work that you distribute or publish,
  1118. X    that in whole or in part contains or is a derivative of this
  1119. X    program or any part thereof, to be licensed at no charge to all
  1120. X    third parties on terms identical to those contained in this
  1121. X    License Agreement (except that you may choose to grant more
  1122. X    extensive warranty protection to third parties, at your option).
  1123. X
  1124. X    c) You may charge a distribution fee for the physical act of
  1125. X    transferring a copy, and you may at your option offer warranty
  1126. X    protection in exchange for a fee.
  1127. X
  1128. X  3. You may copy and distribute this program or any portion of it in
  1129. Xcompiled, executable or object code form under the terms of Paragraphs
  1130. X1 and 2 above provided that you do the following:
  1131. X
  1132. X    a) cause each such copy to be accompanied by the
  1133. X    corresponding machine-readable source code, which must
  1134. X    be distributed under the terms of Paragraphs 1 and 2 above; or,
  1135. X
  1136. X    b) cause each such copy to be accompanied by a
  1137. X    written offer, with no time limit, to give any third party
  1138. X    free (except for a nominal shipping charge) a machine readable
  1139. X    copy of the corresponding source code, to be distributed
  1140. X    under the terms of Paragraphs 1 and 2 above; or,
  1141. X
  1142. X    c) in the case of a recipient of this program in compiled, executable
  1143. X    or object code form (without the corresponding source code) you
  1144. X    shall cause copies you distribute to be accompanied by a copy
  1145. X    of the written offer of source code which you received along
  1146. X    with the copy you received.
  1147. X
  1148. X  4. You may not copy, sublicense, distribute or transfer this program
  1149. Xexcept as expressly provided under this License Agreement.  Any attempt
  1150. Xotherwise to copy, sublicense, distribute or transfer this program is void and
  1151. Xyour rights to use the program under this License agreement shall be
  1152. Xautomatically terminated.  However, parties who have received computer
  1153. Xsoftware programs from you with this License Agreement will not have
  1154. Xtheir licenses terminated so long as such parties remain in full compliance.
  1155. X
  1156. X  5. If you wish to incorporate parts of this program into other free
  1157. Xprograms whose distribution conditions are different, write to the Free
  1158. XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
  1159. Xworked out a simple rule that can be stated here, but we will often permit
  1160. Xthis.  We will be guided by the two goals of preserving the free status of
  1161. Xall derivatives of our free software and of promoting the sharing and reuse of
  1162. Xsoftware.
  1163. X
  1164. X
  1165. XIn other words, you are welcome to use, share and improve this program.
  1166. XYou are forbidden to forbid anyone else to use, share and improve
  1167. Xwhat you give them.   Help stamp out software-hoarding!  */
  1168. X
  1169. Xshort ospeed;                   /* these are defined in case user doesn't */
  1170. Xchar PC;
  1171. X
  1172. END_OF_TEXTERN.C
  1173. if test 5113 -ne `wc -c <TEXTERN.C`; then
  1174.     echo shar: \"TEXTERN.C\" unpacked with wrong size!
  1175. fi
  1176. # end of overwriting check
  1177. fi
  1178. if test -f TPARAM.C -a "${1}" != "-c" ; then 
  1179.   echo shar: Will not over-write existing file \"TPARAM.C\"
  1180. else
  1181. echo shar: Extracting \"TPARAM.C\" \(11046 characters\)
  1182. sed "s/^X//" >TPARAM.C <<'END_OF_TPARAM.C'
  1183. X/* Merge parameters into a termcap entry string.
  1184. X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  1185. X
  1186. X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
  1187. X   Dec 1987 - Mar 1988.
  1188. X
  1189. X               NO WARRANTY
  1190. X
  1191. X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  1192. XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  1193. XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  1194. XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  1195. XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  1196. XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1197. XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  1198. XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  1199. XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  1200. XCORRECTION.
  1201. X
  1202. X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  1203. XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  1204. XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  1205. XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  1206. XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  1207. XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  1208. XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  1209. XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  1210. XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  1211. XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  1212. X
  1213. X        GENERAL PUBLIC LICENSE TO COPY
  1214. X
  1215. X  1. You may copy and distribute verbatim copies of this source file
  1216. Xas you receive it, in any medium, provided that you conspicuously and
  1217. Xappropriately publish on each copy a valid copyright notice "Copyright
  1218. X(C) 1986 Free Software Foundation, Inc."; and include following the
  1219. Xcopyright notice a verbatim copy of the above disclaimer of warranty
  1220. Xand of this License.  You may charge a distribution fee for the
  1221. Xphysical act of transferring a copy.
  1222. X
  1223. X  2. You may modify your copy or copies of this source file or
  1224. Xany portion of it, and copy and distribute such modifications under
  1225. Xthe terms of Paragraph 1 above, provided that you also do the following:
  1226. X
  1227. X    a) cause the modified files to carry prominent notices stating
  1228. X    that you changed the files and the date of any change; and
  1229. X
  1230. X    b) cause the whole of any work that you distribute or publish,
  1231. X    that in whole or in part contains or is a derivative of this
  1232. X    program or any part thereof, to be licensed at no charge to all
  1233. X    third parties on terms identical to those contained in this
  1234. X    License Agreement (except that you may choose to grant more
  1235. X    extensive warranty protection to third parties, at your option).
  1236. X
  1237. X    c) You may charge a distribution fee for the physical act of
  1238. X    transferring a copy, and you may at your option offer warranty
  1239. X    protection in exchange for a fee.
  1240. X
  1241. X  3. You may copy and distribute this program or any portion of it in
  1242. Xcompiled, executable or object code form under the terms of Paragraphs
  1243. X1 and 2 above provided that you do the following:
  1244. X
  1245. X    a) cause each such copy to be accompanied by the
  1246. X    corresponding machine-readable source code, which must
  1247. X    be distributed under the terms of Paragraphs 1 and 2 above; or,
  1248. X
  1249. X    b) cause each such copy to be accompanied by a
  1250. X    written offer, with no time limit, to give any third party
  1251. X    free (except for a nominal shipping charge) a machine readable
  1252. X    copy of the corresponding source code, to be distributed
  1253. X    under the terms of Paragraphs 1 and 2 above; or,
  1254. X
  1255. X    c) in the case of a recipient of this program in compiled, executable
  1256. X    or object code form (without the corresponding source code) you
  1257. X    shall cause copies you distribute to be accompanied by a copy
  1258. X    of the written offer of source code which you received along
  1259. X    with the copy you received.
  1260. X
  1261. X  4. You may not copy, sublicense, distribute or transfer this program
  1262. Xexcept as expressly provided under this License Agreement.  Any attempt
  1263. Xotherwise to copy, sublicense, distribute or transfer this program is void and
  1264. Xyour rights to use the program under this License agreement shall be
  1265. Xautomatically terminated.  However, parties who have received computer
  1266. Xsoftware programs from you with this License Agreement will not have
  1267. Xtheir licenses terminated so long as such parties remain in full compliance.
  1268. X
  1269. X  5. If you wish to incorporate parts of this program into other free
  1270. Xprograms whose distribution conditions are different, write to the Free
  1271. XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
  1272. Xworked out a simple rule that can be stated here, but we will often permit
  1273. Xthis.  We will be guided by the two goals of preserving the free status of
  1274. Xall derivatives of our free software and of promoting the sharing and reuse of
  1275. Xsoftware.
  1276. X
  1277. X
  1278. XIn other words, you are welcome to use, share and improve this program.
  1279. XYou are forbidden to forbid anyone else to use, share and improve
  1280. Xwhat you give them.   Help stamp out software-hoarding!  */
  1281. X
  1282. X
  1283. X/* config.h may rename various library functions such as malloc.  */
  1284. X#ifdef emacs
  1285. X#include "config.h"
  1286. X#else
  1287. X#include <fcntl.h>
  1288. X#endif
  1289. X
  1290. X/* MODS for MS-DOS by Paul Shields, December 1987. */
  1291. X#ifdef MSDOS
  1292. X#include <stdlib.h>
  1293. X#endif
  1294. X
  1295. X/* Assuming STRING is the value of a termcap string entry
  1296. X   containing `%' constructs to expand parameters,
  1297. X   merge in parameter values and store result in block OUTSTRING points to.
  1298. X   LEN is the length of OUTSTRING.  If more space is needed,
  1299. X   a block is allocated with `malloc'.
  1300. X
  1301. X   The value returned is the address of the resulting string.
  1302. X   This may be OUTSTRING or may be the address of a block got with `malloc'.
  1303. X   In the latter case, the caller must free the block.
  1304. X
  1305. X   The fourth and following args to tparam serve as the parameter values.  */
  1306. X
  1307. Xstatic char *tparam1 ();
  1308. X
  1309. X/* VARARGS 2 */
  1310. Xchar *
  1311. Xtparam (string, outstring, len, arg0, arg1, arg2, arg3)
  1312. X     char *string;
  1313. X     char *outstring;
  1314. X     int len;
  1315. X     int arg0, arg1, arg2, arg3;
  1316. X{
  1317. X#ifdef NO_ARG_ARRAY
  1318. X  int arg[4];
  1319. X  arg[0] = arg0;
  1320. X  arg[1] = arg1;
  1321. X  arg[2] = arg2;
  1322. X  arg[3] = arg3;
  1323. X  return tparam1 (string, outstring, len, 0, 0, arg);
  1324. X#else
  1325. X  return tparam1 (string, outstring, len, 0, 0, &arg0);
  1326. X#endif
  1327. X}
  1328. X
  1329. Xchar *BC = 0,
  1330. X     *UP = 0;
  1331. X
  1332. Xstatic char tgoto_buf[50];
  1333. X
  1334. Xchar *
  1335. Xtgoto (cm, hpos, vpos)
  1336. X     char *cm;
  1337. X     int hpos, vpos;
  1338. X{
  1339. X  int args[2];
  1340. X  if (!cm)
  1341. X    return 0;
  1342. X  args[0] = vpos;
  1343. X  args[1] = hpos;
  1344. X  return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
  1345. X}
  1346. X
  1347. Xstatic char *
  1348. Xtparam1 (string, outstring, len, up, left, argp)
  1349. X     char *string;
  1350. X     char *outstring;
  1351. X     int len;
  1352. X     char *up, *left;
  1353. X     register int *argp;
  1354. X{
  1355. X  register int c;
  1356. X  register char *p = string;
  1357. X  register char *op = outstring;
  1358. X  char *outend;
  1359. X  int outlen = 0;
  1360. X
  1361. X  register int tem;
  1362. X  int *oargp = argp;
  1363. X  char *doleft = 0;
  1364. X  char *doup = 0;
  1365. X
  1366. X  outend = outstring + len;
  1367. X
  1368. X  while (1)
  1369. X    {
  1370. X      /* If the buffer might be too short, make it bigger.  */
  1371. X      if (op + 5 >= outend)
  1372. X    {
  1373. X      register char *new;
  1374. X      if (outlen == 0)
  1375. X        {
  1376. X          new = (char *) malloc (outlen = 40 + len);
  1377. X          outend += 40;
  1378. X        }
  1379. X      else
  1380. X        {
  1381. X          outend += outlen;
  1382. X          new = (char *) realloc (outstring, outlen *= 2);
  1383. X        }
  1384. X      op += new - outstring;
  1385. X      outend += new - outstring;
  1386. X      outstring = new;
  1387. X    }
  1388. X      if (!(c = *p++))
  1389. X    break;
  1390. X      if (c == '%')
  1391. X    {
  1392. X      c = *p++;
  1393. X      tem = *argp;
  1394. X      switch (c)
  1395. X        {
  1396. X        case 'd':        /* %d means output in decimal */
  1397. X          if (tem < 10)
  1398. X        goto onedigit;
  1399. X          if (tem < 100)
  1400. X        goto twodigit;
  1401. X        case '3':        /* %3 means output in decimal, 3 digits. */
  1402. X          if (tem > 999)
  1403. X        {
  1404. X          *op++ = tem / 1000 + '0';
  1405. X          tem %= 1000;
  1406. X        }
  1407. X          *op++ = tem / 100 + '0';
  1408. X        case '2':        /* %2 means output in decimal, 2 digits. */
  1409. X        twodigit:
  1410. X          tem %= 100;
  1411. X          *op++ = tem / 10 + '0';
  1412. X        onedigit:
  1413. X          *op++ = tem % 10 + '0';
  1414. X          argp++;
  1415. X          break;
  1416. X
  1417. X        case 'C':
  1418. X          /* For c-100: print quotient of value by 96, if nonzero,
  1419. X         then do like %+ */
  1420. X          if (tem >= 96)
  1421. X        {
  1422. X          *op++ = tem / 96;
  1423. X          tem %= 96;
  1424. X        }
  1425. X        case '+':        /* %+x means add character code of char x */
  1426. X          tem += *p++;
  1427. X        case '.':        /* %. means output as character */
  1428. X          if (left)
  1429. X        {
  1430. X          /* If want to forbid output of 0 and \n,
  1431. X             and this is one, increment it.  */
  1432. X          if (tem == 0 || tem == '\n')
  1433. X            {
  1434. X              tem++;
  1435. X              if (argp == oargp)
  1436. X            outend -= strlen (doleft = left);
  1437. X              else
  1438. X            outend -= strlen (doup = up);
  1439. X            }
  1440. X        }
  1441. X          *op++ = tem | 0200;
  1442. X        case 'f':        /* %f means discard next arg */
  1443. X          argp++;
  1444. X          break;
  1445. X
  1446. X        case 'b':        /* %b means back up one arg (and re-use it) */
  1447. X          argp--;
  1448. X          break;
  1449. X
  1450. X        case 'r':        /* %r means interchange following two args */
  1451. X          argp[0] = argp[1];
  1452. X          argp[1] = tem;
  1453. X          oargp++;
  1454. X          break;
  1455. X
  1456. X        case '>':        /* %>xy means if arg is > char code of x, */
  1457. X          if (argp[0] > *p++) /* then add char code of y to the arg, */
  1458. X        argp[0] += *p;    /* and in any case don't output. */
  1459. X          p++;        /* Leave the arg to be output later. */
  1460. X          break;
  1461. X
  1462. X        case 'a':        /* %a means arithmetic */
  1463. X          /* Next character says what operation.
  1464. X         Add or subtract either a constant or some other arg */
  1465. X          /* First following character is + to add or - to subtract
  1466. X         or = to assign.  */
  1467. X          /* Next following char is 'p' and an arg spec
  1468. X         (0100 plus position of that arg relative to this one)
  1469. X         or 'c' and a constant stored in a character */
  1470. X          tem = p[2] & 0177;
  1471. X          if (p[1] == 'p')
  1472. X        tem = argp[tem - 0100];
  1473. X          if (p[0] == '-')
  1474. X        argp[0] -= tem;
  1475. X          else if (p[0] == '+')
  1476. X        argp[0] += tem;
  1477. X          else if (p[0] == '*')
  1478. X        argp[0] *= tem;
  1479. X          else if (p[0] == '/')
  1480. X        argp[0] /= tem;
  1481. X          else
  1482. X        argp[0] = tem;
  1483. X
  1484. X          p += 3;
  1485. X          break;
  1486. X
  1487. X        case 'i':        /* %i means add one to arg, */
  1488. X          argp[0] ++;    /* and leave it to be output later. */
  1489. X          argp[1] ++;    /* Increment the following arg, too!  */
  1490. X          break;
  1491. X
  1492. X        case '%':        /* %% means output %; no arg. */
  1493. X          goto ordinary;
  1494. X
  1495. X        case 'n':        /* %n means xor each of next two args with 140 */
  1496. X          argp[0] ^= 0140;
  1497. X          argp[1] ^= 0140;
  1498. X          break;
  1499. X
  1500. X        case 'm':        /* %m means xor each of next two args with 177 */
  1501. X          argp[0] ^= 0177;
  1502. X          argp[1] ^= 0177;
  1503. X          break;
  1504. X
  1505. X        case 'B':        /* %B means express arg as BCD char code. */
  1506. X          argp[0] += 6 * (tem / 10);
  1507. X          break;
  1508. X
  1509. X        case 'D':        /* %D means weird Delta Data transformation */
  1510. X          argp[0] -= 2 * (tem % 16);
  1511. X          break;
  1512. X        }
  1513. X    }
  1514. X      else
  1515. X    /* Ordinary character in the argument string.  */
  1516. X      ordinary:
  1517. X    *op++ = c;
  1518. X    }
  1519. X  *op = 0;
  1520. X  if (doleft)
  1521. X    strcpy (op, doleft);
  1522. X  if (doup)
  1523. X    strcpy (op, doup);
  1524. X  return outstring;
  1525. X}
  1526. X
  1527. X#ifdef TEST
  1528. X
  1529. Xmain (argc, argv)
  1530. X     int argc;
  1531. X     char **argv;
  1532. X{
  1533. X  char buf[50];
  1534. X  int args[3];
  1535. X  args[0] = atoi (argv[2]);
  1536. X  args[1] = atoi (argv[3]);
  1537. X  args[2] = atoi (argv[4]);
  1538. X  tparam1 (argv[1], buf, "LEFT", "UP", args);
  1539. X  printf ("%s\n", buf);
  1540. X  return 0;
  1541. X}
  1542. X
  1543. X#endif /* TEST */
  1544. END_OF_TPARAM.C
  1545. if test 11046 -ne `wc -c <TPARAM.C`; then
  1546.     echo shar: \"TPARAM.C\" unpacked with wrong size!
  1547. fi
  1548. # end of overwriting check
  1549. fi
  1550. echo shar: End of shell archive.
  1551. exit 0
  1552.